<%@ page language="java" contentType="text/html; charset=utf-8"	pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/jsp/common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>订单管理 - 红高粱</title>
<%@ include file="/WEB-INF/jsp/common/res.jsp" %>
<link rel="stylesheet" type="text/css" href="<c:url value="/easyui/default/easyui.css"/>" />
<script type="text/javascript" src="<c:url value="/easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/easyui/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript" src="<c:url value="/widgets/My97DatePicker/WdatePicker.js"/>"></script>
<style type="text/css">
#_order{background-color:#0087d8;}
.operation{}
.p_info{height: 20px;}
.p_info span{margin-left: 5px;}
a{border: 0px;}
.data_info{width:450px;border: 1px solid #ccc;}
</style>
</head>
<body style="overflow-x:hidden;">
<%@ include  file="/WEB-INF/jsp/common/header.jsp" %>
<div class="main">
	<div class="main_title">
			<div class="main_title2"><span>当前位置：订单管理 &gt; 订单信息</span></div>
	</div>
	<div class="main_content">
		<div class="main_menu" >
			<ul>
				<li class="choice"><a href="#" style="color: #FFFFFF;">订单信息</a></li>
				<li><a href="#"></a></li>
			</ul>
		</div>
		<div class="main_list" style="height: 500px;">
			<div class="query">
			<div style="margin: 0 auto;">
				<p style="margin-left: 13px;">
				<span>电话：<input type="text" autocomplete="off" placeholder="移动电话" id="phone" value="${param['phone']}"/></span>
				<span>订单号：<input type="text" autocomplete="off" placeholder="订单号..." id="order_no" value="${param['order_no']}"/></span>
				<span>下单时间：<input type="text" placeholder="起始时间" name="start_date" value="${param['start_date']}" class="Wdate"
					onFocus="WdatePicker({startDate:'%y-%M-01 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})" /></span>
				<span>至：<input type="text" placeholder="结束时间" name="end_date" value="${param['end_date']}" class="Wdate"
					onFocus="WdatePicker({startDate:'%y-%M-01 23:59:59',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})"/></span>
				<c:if test="${customer.type eq 1}">
					<span>店铺：<select name="categories" class="menu" id="categories">
									<option value="">---请选择---</option>
									<option value="red">红客会</option>
									<c:forEach var="m" items="${categories}">
									<option value="${m.name}">${m.name}</option>
									</c:forEach>
								</select></span>
				</c:if>
				</p>
				<p style="margin-left: 13px;">
				<input type="hidden" id="pay_status" value="${param['pay_status']}"/>
				<input type="hidden" id="pay_way" value="${param['pay_way']}" />
				<input type="hidden" id="delivery_status" value="${param['delivery_status']}"/>
				<span>
				支付状态：<input type="checkbox" id="pay_status_no" <c:if test="${param['pay_status'] eq 0}">checked="checked" value="yes"</c:if>/>未支付
				 <input type="checkbox" id="pay_status_yes" <c:if test="${param['pay_status'] eq 1}">checked="checked" value="yes"</c:if>/>已支付</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<span>
				支付方式：<input type="checkbox" id="pay_way_arrival" <c:if test="${param['pay_way'] eq 2}">checked="checked" value="yes"</c:if>/>
				到店支付	<input type="checkbox" id="pay_way_online" <c:if test="${param['pay_way'] eq 1}">checked="checked" value="yes"</c:if>/>
				在线支付</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<span>
				配送状态：<input type="checkbox" id="delivery_status_no" <c:if test="${param['delivery_status'] eq 1}">checked="checked" value="yes"</c:if>/>
				未配送	<input type="checkbox" id="delivery_status_ing" <c:if test="${param['delivery_status'] eq 2}">checked="checked" value="yes"</c:if>/>
				配送中<input type="checkbox" id="delivery_status_yes" <c:if test="${param['delivery_status'] eq 3}">checked="checked" value="yes"</c:if>/>已送达</span>
				</p>
				<p style="margin-left: 13px;">
				<a href="javascript:query();" class="btn">查询</a>
				</p>
			</div>
			</div>
			<div class="operation"></div>
			<table  width="98%" border="0" cellspacing="0" cellpadding="0" class="dataTable">
				<thead>
		              <tr>
		                <th  style="border-left: 1px solid #ccc;">编号</th>
		                <th >联系电话</th>
		                <th >店铺</th>
		                <th >总价</th>
		                <th >支付方式</th>
		                <th >支付状态</th>
		                <th >下单时间</th>
		                <th >配送状态</th>
		                <th style="display:none;">人数</th>
		                <th style="display:none;">到店时间</th>
		               <!--  <th >使用积分</th>--> 
		                <th >操作</th>
		              </tr>
		        </thead>
		        <tbody>
		              <c:forEach var="o" items="${orders}" varStatus="var">
		              <tr <c:if test="${var.index%2 eq 0}">style="background-color:#F4F4F4"</c:if>>
		              	<td style="border-left:1px solid #ccc;">${var.index + 1}</td>
		              	<td>${o.tel}</td>
		              	<td>${o.toAddress}</td>
		              	<td>￥${o.totalPrice}</td>
		              	<td>
		              		<c:if test="${o.payType eq 1}"><span style="color:red;">在线支付</span></c:if>
		              		<c:if test="${o.payType eq 2}"><span style="color:green;">到店支付</span></c:if>
		              	</td>
		              	<td>
		              		<c:if test="${o.payStatus eq 1}"><span style="color:green;">已支付</span></c:if>
		              		<c:if test="${o.payStatus eq 0}"><span style="color:red;">未支付</span></c:if>
		              	</td>
		              	<td>
		              		<fmt:formatDate value="${o.date}" pattern="yyyy-MM-dd HH:mm" />
		              	</td>
		              	<td>
		              		<c:if test="${o.sendStatus eq 1}"><span style="color:red;">未配送</span></c:if>
		              		<c:if test="${o.sendStatus eq 2}"><span style="color:green;">配送中</span></c:if>
		              		<c:if test="${o.sendStatus eq 3}">已送达</c:if>
		              	</td>
		              	<td style="display:none;">${o.peopleCount }</td>
		              	<td style="display:none;">${o.arriveTime }</td>
		              	<!-- <td>${o.credits }</td>--> 
		              	<td style="border-right:1px solid #ccc;">
		              		<c:if test="${o.sendStatus eq 1}">
		              			<a href="javascript:" data-orderId="${o.orderId}" name="send_order">[配送]</a>
		              		</c:if> 
		              		<c:if test="${o.sendStatus eq 2}">
		              			<a href="javascript:" data-orderId="${o.orderId}" name="send_yes">[已送达]</a>
		              		</c:if>
		              		<a href="javascript:" data-products='${o.products}'  name="product_info" data-orderId="${o.orderId}" data-phone="${o.tel}" data-deliver="${o.sendStatus}" data-memo="${o.memo}" 
		              		
		              		data-name="${o.name}"  data-redAddress="${o.address}" >[详情]</a>
		              	</td>
		              </tr>	
		              </c:forEach>
		       </tbody>
		       </table>
		       <div class="bottom_page">
		       		<c:if test="${len lt 1}">
						<p style="text-align: center; font-size:14px;">对不起，没有符合条件的信息</p>
					</c:if>
					<c:if test="${len gt 0}">
					   <p>
						<c:if test="${page eq 1}">
							<a href="javascript:" style="color: #ccc;">首页</a>&nbsp;
							<a href="javascript:" style="color: #ccc;">上一页</a>
					</c:if>
					<c:if test="${page gt 1}">
							<a href="<c:url value="/order/query?phone=${param['phone']}&start_date=${param['start_date']}&end_date=${param['end_date']}&pay_status=${param['pay_status']}&pay_way=${param['pay_way']}&delivery_status=${param['delivery_status']}&toAddress=${param['toAddress']}"/>">首页</a>&nbsp;
							<a href="<c:url value="/order/query?page=${page -1}&phone=${param['phone']}&start_date=${param['start_date']}&end_date=${param['end_date']}&pay_status=${param['pay_status']}&pay_way=${param['pay_way']}&delivery_status=${param['delivery_status']}&toAddress=${param['toAddress']}"/>">上一页</a>
					</c:if>
					<c:if test="${page lt pageTotal}">
							<a href="<c:url value="/order/query?page=${page +1}&phone=${param['phone']}&start_date=${param['start_date']}&end_date=${param['end_date']}&pay_status=${param['pay_status']}&pay_way=${param['pay_way']}&delivery_status=${param['delivery_status']}&toAddress=${param['toAddress']}"/>">下一页</a>&nbsp;
							<a href="<c:url value="/order/query?page=${pageTotal}&phone=${param['phone']}&start_date=${param['start_date']}&end_date=${param['end_date']}&pay_status=${param['pay_status']}&pay_way=${param['pay_way']}&delivery_status=${param['delivery_status']}&toAddress=${param['toAddress']}"/>">尾页</a>
					</c:if>
					<c:if test="${page >= pageTotal}">
							<a href="javascript:" style="color: #ccc;">下一页</a>&nbsp;
							<a href="javascript:" style="color: #ccc;">尾页</a>
					</c:if>
					&nbsp;&nbsp;
					<span style="color:#ccc;font-size: 12px;">当前第${page}页/共${pageTotal}页/共${total}条记录</span>	
					</p>	
					</c:if>
		       </div>
		</div>
	</div>
	<div id="order_window" class="easyui-window" style="width:500px;height:300px;padding:10px;" title="详细信息" data-options="modal:true,minimizable:false,maximizable:false,collapsible:false,closed:true">
		<div id="info">
		</div>
	</div>
</div>
<script type="text/javascript">
$(function(){
	$("#pay_status_no").click(function(){
		var cd = $(this).val();
		if(cd == "on"){
			$(this).val("yes");
			$("#pay_status").val("0");
		}
		if(cd == "yes"){
			$(this).val("no");
			$("#pay_status").val("");
		}
		$("#pay_status_yes").attr("checked",false);
	});
	$("#pay_status_yes").click(function(){
		var cd = $(this).val();
		if(cd == "on"){
			$(this).val("yes");
			$("#pay_status").val("1");
		}
		if(cd == "yes"){
			$("#pay_status").val("");
		}
		$("#pay_status_no").attr("checked",false);
	});
	$("#pay_way_arrival").click(function(){
		var cd = $(this).val();
		if(cd == "on"){
			$(this).val("yes");
			$("#pay_way").val("2");
		}
		if(cd == "yes"){
			$("#pay_way").val("");
		}
		$("#pay_way_online").attr("checked",false);
	});
	$("#pay_way_online").click(function(){
		var cd = $(this).val();
		if(cd == "on"){
			$(this).val("yes");
			$("#pay_way").val("1");
		}
		if(cd == "yes"){
			$("#pay_way").val("");
		}
		$("#pay_way_arrival").attr("checked",false);
	});
	$("#delivery_status_no").click(function(){
		var cd = $(this).val();
		if(cd == "on"){
			$(this).val("yes");
			$("#delivery_status").val("1");
		}
		if(cd == "yes"){
			$("#delivery_status").val("");
		}
		$("#delivery_status_ing").attr("checked",false);
		$("#delivery_status_yes").attr("checked",false);
	});
	$("#delivery_status_ing").click(function(){
		var cd = $(this).val();
		if(cd == "on"){
			$(this).val("yes");
			$("#delivery_status").val("2");
		}
		if(cd == "yes"){
			$("#delivery_status").val("");
		}
		$("#delivery_status_no").attr("checked",false);
		$("#delivery_status_yes").attr("checked",false);
	});
	$("#delivery_status_yes").click(function(){
		var cd = $(this).val();
		if(cd == "on"){
			$(this).val("yes");
			$("#delivery_status").val("3");
		}
		if(cd == "yes"){
			$("#delivery_status").val("");
		}
		$("#delivery_status_no").attr("checked",false);
		$("#delivery_status_ing").attr("checked",false);
	});
	//订单详情
	$("a[name='product_info']").click(function(){
		var json = $(this).attr("data-products");
		var products = JSON.parse(json);
		var html = "<h4>订单编号："+$(this).attr("data-orderId")+"&nbsp;&nbsp:联系电话："+$(this).attr("data-phone")+"</h4>";
		html+="<table cellspacing='0' cellpadding='0' class='data_info' border='1'><th>产品名称：</th><th>产品单价：</th><th>购买数量：</th>";
		for(var i = 0;i < products.length;i++){
			html+="<tr class='p_info'>";
			html+="<td>"+products[i].name+"</td>";
			html+="<td>￥"+products[i].price+"</td>";
			html+="<td>"+products[i].number+"</td>";
			html+="</tr>";
		}
		var dinfo = $(this).attr("data-deliver");
		if(dinfo == 1){
			dinfo = "未配送";
		}
		if(dinfo == 2){
			dinfo = "配送中";
		}
		if(dinfo == 3){
			dinfo = "已配送";
		}
		html+="<h4>客户姓名: "+$(this).attr("data-name")+"</h4>";
		html+="<h4>物流信息："+dinfo+"</h4>";
		html+="<h4>配送地址："+ $(this).attr("data-redAddress") +"</h4>";
		html+="<h4>备注："+$(this).attr("data-memo")+"</h4>";
		html +="</table>";
		$("#info").html(html);
		$("#order_window").window("open");
	});
	//发送订单
	$("a[name='send_order']").click(function(){
		var orderId = $(this).attr("data-orderId");
		$.messager.confirm("提示","是否配送订单"+orderId,function(r){
			if(r){
				$.ajax({
					url:"<c:url value="/order/send"/>",
					type:"POST",
					data:{orderId:orderId,status:"go"},
					success:function(data){
						if(data.ok){
							window.location.reload(true);
						}else{
							$.messager.alert("提示!",data.msg,"error");
						}
					},error:function(){
						$.messager.alert("提示!","网络错误,请稍后再试!","error");
					}
				});
			}
		});
	});
	//完成配送
	$("a[name='send_yes']").click(function(){
		var orderId = $(this).attr("data-orderId");
		$.messager.confirm("提示","确认订单"+orderId+"已经配送成功!",function(r){
			if(r){
				$.ajax({
					url:"<c:url value="/order/send"/>",
					type:"POST",
					data:{orderId:orderId,status:"yes"},
					success:function(data){
						if(data.ok){
							window.location.reload(true);
						}else{
							$.messager.alert("提示!",data.msg,"error");
						}
					},error:function(){
						$.messager.alert("提示!","网络错误,请稍后再试!","error");
					}
				});
			}
		});
	});
});

//查询
function query(){
	var phone =  $("#phone").val();
	var start_date = $("input[name='start_date']").val();
	var end_date = $("input[name='end_date']").val();
	var order_no = $("#order_no").val();
	var pay_status = $("#pay_status").val();
	var pay_way = $("#pay_way").val();
	var delivery_status = $("#delivery_status").val();
	var toAddress = $("#categories").val();
	window.location.href = "<c:url value="/order/query"/>?phone="+phone+"&start_date="+start_date+"&end_date="+end_date+"&order_no="+order_no+"&pay_status="+pay_status+"&pay_way="+pay_way+"&delivery_status="+delivery_status+"&toAddress="+toAddress;
}
</script>
</body>
</html>